package com.itheima;

import com.itheima.config.ThreadPoolConfig;
import com.itheima.controller.MainFxml;
import com.itheima.controller.MediaViewFx;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.Objects;
// 学一下javafx   java 版本太高了 javafx被独立出来了
public class Main extends Application {

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        scene1();
    }
    void scene1() throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        // 设置加载的fxml文件的位置
        fxmlLoader.setLocation(Objects.requireNonNull(getClass().getResource("/mainFxml.fxml")));

        Parent load = fxmlLoader.load();
        MainFxml controller = fxmlLoader.getController();
        controller.imageBu.setOnMouseClicked(event -> {
                //跳转到bilibili
                Platform.runLater(() -> {
                    getHostServices().showDocument("https://www.bilibili.com/");
                });
        });
        Scene scene = new Scene(load);
        Stage stage = new Stage();
        stage.setScene(scene);
        stage.setTitle("Spider from Bilibili");
        //设置图标
        stage.getIcons().add(new Image("/image/img.png"));

        //不能改变窗口大小
        stage.setResizable(false);
        stage.setOnCloseRequest(event -> {
            //关闭线程池，释放资源
            ThreadPoolConfig.getThreadPool().shutdown();
            //退出程序
            Platform.exit();
        });
        stage.show();

        //test

    }

}